﻿using System;

namespace Developmentalmadness.Web.UI.AjaxAbstractions
{
    /// <summary>
    /// This is an implementation of the internal ScriptKey object used by the .NET framework
    /// so we can try and stick as close to the framework implementation as possible
    /// </summary>
    internal class ScriptKey
    {
        private Type _type;
        private String _key;
        private Boolean _isInclude;

        public ScriptKey(Type type, String key)
            : this(type, key, false)
        {

        }

        public ScriptKey(Type type, String key, Boolean isInclude)
        {
            _type = type;
            _key = key;
            _isInclude = isInclude;
        }

        public override bool Equals(object obj)
        {
            ScriptKey key = (ScriptKey)obj;

            if (!(key._key == _key))
                return false;

            if (!(key._type == _type))
                return false;

            if (!(key._isInclude == _isInclude))
                return false;

            return true;
        }

        public override int GetHashCode()
        {
            return CombineHashCodes(CombineHashCodes(_type.GetHashCode(), _key.GetHashCode()), _isInclude.GetHashCode());
        }

        private static int CombineHashCodes(int h1, int h2)
        {
            return (((h1 << 5) + h1) ^ h2);
        }
    }

}
